import {CommonFunction} from "./CommonFunction";
import {GlobalClass} from "./GlobalClass";
import { EventDefinition } from "./EventDefinition";
import { GlobalDefinition } from "./GlobalDefinition";
import { DrawClass } from "./DrawClass";
import { OG } from "./CommonClass";
import { MainCanvasClass } from "./MianCanvasClass";
/**右顶部功能框类 */
export class RightTopClass {
    private RightTop:HTMLDivElement;
    private DropElem:HTMLElement;  //文件拖放对象
    private CurrentElem:HTMLElement;  //点击选中的元素
    
    public constructor () {
        this.InitFunc();
    }

    /**初始化 */
    private InitFunc () {
        this.RightTop = CommonFunction.ins().IdToElement("topFunc") as HTMLDivElement;
        GlobalClass.ListenerCenter.addEvent(EventDefinition.CLICK,this.RightTop,this.onClick.bind(this));
        GlobalClass.FileDisposClass.BindLabelDrop(this.DropElem ,"bottomFunc",this.RightTop);
    }

    /**标记选中的元素
    * @param ele_select 选中元素
    * @param ele_parent 标签所在的父对象
    */ 
    public TagElement (ele_select:HTMLElement, ele_parent:HTMLElement) {
        //判断中的标签是否在指定父节点内
        if(ele_select.parentElement == ele_parent) {
            ele_select.style.backgroundColor = "#f6aff2";
        }
    }

    private onClick (event,e) {
        let curr_Id:string = e.path[1].id;
        //若上次有选择图块对象则将其背景重置为白色
        if(this.CurrentElem != null) {
            if(this.CurrentElem.parentElement == this.RightTop) {
                this.CurrentElem.style.backgroundColor = "#ffffff";
            }
        }
        this.CurrentElem = e.path[1];
        this.TagElement(this.CurrentElem,this.RightTop);
        MainCanvasClass.ins().SettingImage(this.CurrentElem.childNodes[0]);
    }
} 